﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using MockPrjTeam2.DAO;
using MockPrjTeam2.Entity;

namespace MockPrjTeam2.Biz
{
    public class TrustDistrictBiz
    {
        private TrustDistrictDao trustDistrictDao;
        public TrustDistrictBiz()
        {
            trustDistrictDao = new TrustDistrictDao();
        }

        //method GetAllTrustDistrict()
        public DataTable GetAllTrustDistrict()
        {
            return trustDistrictDao.GetAll();
        }

        //method GetTrustDistrictInActive()
        public DataTable GetTrustDistrictInActive(int id)
        {
            return trustDistrictDao.GetInActive(id);
        }

        
        public DataTable StartWithByNames(string startWith, int flag, int id)
        {
            return trustDistrictDao.StartWithByNames(startWith, flag, id);
        }

        //Method SetActiveTrustDistrict()
        public bool SetActiveTrustDistrict(int trustDistrictId, bool status)
        {
            return trustDistrictDao.SetActive(trustDistrictId, status);
        }

        public bool SetInActive(int trustDistrictId, bool status)
        {
            return trustDistrictDao.SetInActive(trustDistrictId, status);
        }

        //method GetTrustDistrictById()
        public TrustDistrict GetTrustDistrictById(int trustDistrictId)
        {
            TrustDistrict trustDistrict = new TrustDistrict();
            DataTable dt = new DataTable();
            dt = TrustDistrictDao.Instance.GetById(trustDistrictId);
            foreach (DataRow dr in dt.Rows)
            {

                trustDistrict.TrustDistrictName = dr["TrustDistrictName"].ToString();
                trustDistrict.DescriptionDistrict = dr["DescriptionDistrict"].ToString();
                trustDistrict.TrustDistrictID = Convert.ToInt32(dr["TrustDistrictID"]);
                trustDistrict.TrustRegionName = dr["TrustRegionName"].ToString();
                trustDistrict.TrustRegionID = Convert.ToInt32(dr["TrustRegionID"]);
            }
            return trustDistrict;
        }

        //method UpdateTrustDistrict()
        public bool UpdateTrustDistrict(TrustDistrict trustDistrict)
        {
            return trustDistrictDao.UpdateTrustDistrict(trustDistrict);
        }

        //method AddTrustDistrict()
        public bool AddTrustDistrict(TrustDistrict trustDistrict)
        {
            var newId = trustDistrictDao.AddTrustDistrict(trustDistrict);
            return newId;
        }

        public DataTable GetTrustDistrictById1(int trustDistrictId)
        {
            TrustDistrict trustDistrict = new TrustDistrict();
            DataTable dt = new DataTable();
            dt = TrustDistrictDao.Instance.GetById1(trustDistrictId);
            return dt;
        }
        //method CheckTrustDistrictNameExist()
        public int CheckTrustDistrictNameExist(string trustDistrictName)
        {
            return trustDistrictDao.CheckNameExist(trustDistrictName);
        }
    }
}
